<?
//引入所有子系统信息
include_once("../../../common/script/extender_import.php");

//获取板块的设置
include_once("model/setting.php");


//根据筛选框传递过来的内容，组装查找语句
include_once("script/set_condition.php");


//根据页面信息，组装查找语句
include_once("script/set_page.php");


//根据页面数量信息，筛选信息，创造url，供页码使用
include_once("script/set_url.php");



//获取数据。注意带上翻页，搜索，排序等数据
$data_list=select_lines_all_items($table_prefix."website_data","nid desc",$_condition,"$_data_start,$_quantity_per_page");
$data['data_list']=$data_list;





//循环这些网址，访问其对应的api，查看是否已经删除admin账号，如果没有，则前端应该有链接，用于重置账密
foreach($data['data_list'] as $key => $value)
{




    $_url="https://evo.enpingshi.com/api/console/system/check_admin_account.php?domain=".$value['name'];


    $ch = curl_init($_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    //补充ua
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36');
    $response = curl_exec($ch);
    if ($response === false) {
        $errorCode = curl_errno($ch);  // 获取错误代码
        echo "Curl error code: $errorCode\n";
        echo "Curl error: " . curl_error($ch) . "\n";
    }
    curl_close($ch);
    $_sync_domain = $response;

    //$_sync_domain转换成数组
    $_sync_domain = json_decode($_sync_domain, true);


    $data['data_list'][$key]['default_admin_status']="evo have / ".$_sync_domain['info'];


    if (empty($_sync_domain) || ($_sync_domain['info'] ==" ") || ($_sync_domain['info'] ==""))
    {

        if (!function_exists('curl_init')) {
            die("cURL 扩展未启用，请检查 PHP 配置");
        }


        // 尝试重新请求一次
        $_url="https://".$value['name']."/api/console/system/check_admin_account.php?domain=".$value['name'];

        $ch = curl_init($_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        //补充ua
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36');
        $response = curl_exec($ch);
        if ($response === false) {
            $errorCode = curl_errno($ch);  // 获取错误代码
            echo "Curl error code: $errorCode\n";
            echo "Curl error: " . curl_error($ch) . "\n";
        }
        curl_close($ch);
        $_sync_domain = $response;
        $data['data_list'][$key]['default_admin_status'] = "no evo / ".$_sync_domain;

        //print_r($_sync_domain);
    }


}





$_list=select_lines_all_items($table_prefix."website_data","nid desc",'1 = 1 ',"");
$_domain_list=transform_2darray_in_1darray_number_as_key($_list, "domain");

$_sync_domain = file_get_contents("https://evo.enpingshi.com/api/console/system/domain_list.php");
//这里没有evolution了。
//$_sync_domain_arrow = file_get_contents("https://evo.arrow.enpingshi.com/api/console/system/domain_list.php");
$_sync_domain_crossbow = file_get_contents("https://evo.crossbow.enpingshi.com/api/console/system/domain_list.php");

//提取$sync_domain中的data的数据，转化成数组
    $_sync_domain           = json_decode($_sync_domain, true);
    //$_sync_domain_arrow    = json_decode($_sync_domain_arrow, true);
    $_sync_domain_crossbow = json_decode($_sync_domain_crossbow, true);



    //合并数组
    $_sync_domains= array_merge($_sync_domain['data'],$_sync_domain_crossbow['data']);


    //$sync_domain 的 key 和 $data_list 中的domain做比较，找到没有的，就写入数据库 website_data 表


    foreach ($_sync_domains as $key => $value)
    {

        if (!in_array($key, $_domain_list))
        {

            //echo "这个要插入 $key <br/>";
            $_sql=insert_data($table_prefix."website_data",array("ai_name"=>$key,"ai_domain"=>$key,"ai_theme_folder"=>$value,"date"=>date("Y-m-d H:i:s")));
            $_sql_result=mysql_query($_sql) or die("数据写入失败".mysql_error());

        }
    }


foreach ($_sync_domains['site_theme_folder'] as $key => $value)
{

    if (!in_array($key, $_domain_list))
    {

        //echo "这个要插入 $key <br/>";
        $_sql=insert_data($table_prefix."website_data",array("ai_name"=>$key,"ai_domain"=>$key,"ai_theme_folder"=>$value,"date"=>date("Y-m-d H:i:s")));
        $_sql_result=mysql_query($_sql) or die("数据写入失败".mysql_error());

    }
}



?>

